Geospatial data visualisation in Python¶

By Dr. Adam Symington (PythonMaps)¶

alt text

alt text

Background¶

  • Undergraduate Chemistry
  • PhD in Computational Chemistry
  • Focus on materials modelling

My Background

Background¶

  • 7 years working in geospatial data science
  • Specialising in maritime domain awreness
  • https://www.synmax.com/careers/

My Background

Background¶

  • Follow PythonMaps on social media.
  • Give workshops and create educational material on geospatial data viz.
  • https://locatepress.com/book/pymaps

My Background

Download Tutorial Materials¶

This GitHub repository is all that is needed in terms of tutorial content. The simplest solution is to download the material using this link:

https://github.com/symmy596/Scipy2025_workshop/archive/refs/heads/main.zip

If you are familiar with Git, you can also clone this repository with:

$ git clone https://github.com/symmy596/Scipy2025_workshop.git

It will create a new folder named Scipy2025_workshop with all the content you will need.

There are a number of datasets required for these tutorials. These will need to all be downloaded prior to the tutorial and placed in the resources folder.

Required Data Sources¶

Tutorial 1 Vector Data¶

  • Hydrorivers
  • Hydrobasins
  • Natural Earth Country Boundaries

Tutorial 2 Raster¶

  • Forests
  • Natural Earth Country Boundaries

Tutorial 3 Advanced Rasters¶

  • Topography
  • Natural Earth Country Boundaries

Libraries¶

The following libraries are required to run the workshop

  • geopandas==0.10.2
  • pandas==1.4.2
  • numpy==1.21.5
  • shapely==1.8.0
  • matplotlib==3.5.1
  • cartopy==0.20.2
  • rasterio==1.2.10
  • rioxarray==0.11.1
  • gdal==3.5.2
  • xarray==2022.9.0
  • pyarrow==9.0.0

Tutorial One - Vector Data¶

This task will involve reading, manipulating, and plotting linestring and polygon data. There will be a brief introduction on the task at hand and a run through of the tutorial as well as a brief discussion around the finer points of data visualisation.

Attendees will use the hydrosheds rivers dataset to plot rivers and river basins of countries and/or continents (the example uses Brazil).

Learning Outcomes¶
  • Read common vector formats (Shapefile, GeoJSON, GeoPackage) in GeoPandas.
  • Understand how to manipulate vector data, e.g. spatial joins
  • Understand how to plot vector data with GeoPandas.
  • Apply cartographic styling (colour, linewidth) based on attribute data.

Tutorial Two - Raster Data¶

There will be a brief introduction on raster data using a forest geotiff dataset. We will cover the main features for working with raster, namely, plotting, reprojecting, masking and combining them with vector data.

In the tutorial you will generate a map of the world's forests and you will reproject this using rioxarray. You will then mask it to generate map of a specific country. Finally, you will combine it with the rivers dataset from the previous tutorial to make a river/forest map.

Learning outcomes:¶
  • Understand how to read and manipulate raster data with Rasterio and rioxarray.
  • Understand how to plot raster data with Rasterio and Matplotlib
  • Understand how to reproject raster data with rioxarray.

Advanced Rasters¶

Time dependent. We have explored both vector data and raster data. In this exercise we will convert rasters into Points, Linestrings and Polygons using rasterio and GDAL.

In the tutorial you will convert a topography raster into a geodataframe of points, with each elevation value. You will convert a raster into a contour map, with Linestrings for each elevation value. Finally, you guessed it, you will convert a raster into a geodataframe with Polygons for each elevation value.

We will end by trying to combine all of the tutorials into one to create something that starts to look like proper map.

Learning outcomes:¶
  • Understand how to convert a raster to Points with rasterio and Geopandas
  • Understand how to convert a raster to Linestrings with GDAL
  • Understand how to convert a raster to Polygons with GDAL